home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / MATH2 / NINV.PAS < prev    next >
Pascal/Delphi Source File  |  1985-05-17  |  3KB  |  80 lines

  1. (*-------------------------------------------------------------------------*)
  2. (*          Ninv -- Find Percentage Point of Normal Distribution           *)
  3. (*-------------------------------------------------------------------------*)
  4.  
  5. FUNCTION Ninv( P : REAL ) : REAL;
  6.  
  7. (*-------------------------------------------------------------------------*)
  8. (*                                                                         *)
  9. (*       Function:  Ninv                                                   *)
  10. (*                                                                         *)
  11. (*       Purpose:   Finds percentage point of normal distribution          *)
  12. (*                  (low accuracy)                                         *)
  13. (*                                                                         *)
  14. (*       Calling Sequence:                                                 *)
  15. (*                                                                         *)
  16. (*            Perc  := Ninv( P : REAL ) : REAL;                            *)
  17. (*                                                                         *)
  18. (*                 P      --- input probability                            *)
  19. (*                 Perc   --- resultant percentage point                   *)
  20. (*                                                                         *)
  21. (*       Calls:  None                                                      *)
  22. (*                                                                         *)
  23. (*       Remark:  This method provides about 6.5 decimal digits of         *)
  24. (*                accuracy.                                                *)
  25. (*                                                                         *)
  26. (*-------------------------------------------------------------------------*)
  27.  
  28. CONST
  29.    Lim = 1.0E-20;
  30.  
  31. VAR
  32.    Y:  REAL;
  33.    Pr: REAL;
  34.    Nv: REAL;
  35.  
  36. (* Structured *) CONST
  37.  
  38.    PN:  ARRAY[1..5] OF REAL =
  39.         ( -0.322232431088  ,
  40.           -1.0             ,
  41.           -0.342242088547  ,
  42.           -0.0204231210245 ,
  43.           -0.453642210148E-4 );
  44.  
  45.    QN:  ARRAY[1..5] OF REAL =
  46.         ( 0.0993484626060 ,
  47.           0.588581570495  ,
  48.           0.531103462366  ,
  49.           0.103537752850  ,
  50.           0.38560700634E-2  );
  51.  
  52. BEGIN (* Ninv *)
  53.  
  54.    Ninv   := 0.0;
  55.  
  56.    IF( P > 0.5 ) THEN
  57.       Pr := 1.0 - P
  58.    ELSE
  59.       Pr := P;
  60.  
  61.    IF( ( Pr >= Lim ) AND ( Pr <> 0.5 ) ) THEN
  62.  
  63.       BEGIN
  64.  
  65.          Y      := SQRT ( LN( 1.0 / Pr / Pr ) );
  66.  
  67.          Nv     := Y + ((((Y * PN[ 5 ] + PN[ 4 ]) * Y + PN[ 3 ] ) * Y
  68.                                        + PN[ 2 ]) * Y + PN[ 1 ] ) /
  69.                        ((((Y * QN[ 5 ] + QN[ 4 ]) * Y + QN[ 3 ] ) * Y
  70.                                        + QN[ 2 ]) * Y + QN[ 1 ] );
  71.  
  72.          IF( P < 0.5 ) THEN
  73.             Ninv := -Nv
  74.          ELSE
  75.             Ninv := Nv;
  76.  
  77.       END;
  78.  
  79. END   (* Ninv *);
  80.